2020-2021 Sunseeker Telemetry and Lighting System
eusci_b_i2c_ex4_masterTxSingle.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
69 //
70 //*****************************************************************************
71 //*****************************************************************************
72 //
73 //Set the address for slave module. This is a 7-bit address sent in the
74 //following format:
75 //[A6:A5:A4:A3:A2:A1:A0:RS]
76 //
77 //A zero in the "RS" position of the first byte means that the master
78 //transmits (sends) data to the selected slave, and a one in this position
79 //means that the master receives data from the slave.
80 //
81 //*****************************************************************************
82 #define SLAVE_ADDRESS 0x48
83 
84 uint8_t transmitData;
85 
86 void main (void)
87 {
88  WDT_A_hold(WDT_A_BASE);
89 
90  //Set the XT1 frequency to UCS
91  UCS_setExternalClockSource(32768, 0);
92 
93  //Configure Pins for I2C (UCB0SCL, UCB0SDA)
94  //Set P2.5 and P2.6 as Module Function Input
95  GPIO_setAsPeripheralModuleFunctionInputPin(
96  GPIO_PORT_P2,
97  GPIO_PIN5 + GPIO_PIN6
98  );
99 
100  //Initialize transmit data packet
101  transmitData = 0x01;
102 
103  //Initialize Master
104  EUSCI_B_I2C_initMasterParam param = {0};
105  param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
106  param.i2cClk = UCS_getSMCLK();
107  param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_400KBPS;
108  param.byteCounterThreshold = 1;
109  param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
110  EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);
111 
112  //Specify slave address
113  EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE,
115  );
116 
117  //Set in transmit mode
118  EUSCI_B_I2C_setMode(EUSCI_B0_BASE,
119  EUSCI_B_I2C_TRANSMIT_MODE
120  );
121 
122  //Enable I2C Module to start operations
123  EUSCI_B_I2C_enable(EUSCI_B0_BASE);
124 
125  while (1)
126  {
127  //Send single byte data.
128  EUSCI_B_I2C_masterSendSingleByte(EUSCI_B0_BASE,
130  );
131 
132  //Delay until transmission completes
133  while (EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE)) ;
134 
135  //Delay between each transaction
136  __delay_cycles(50);
137 
138  //Increment transmit data counter
139  transmitData++;
140  }
141 }
142 
143 
void main(void)
uint8_t transmitData
#define SLAVE_ADDRESS
MPU_initThreeSegmentsParam param
__delay_cycles(500000)